package com.flca.frw.zk.comp;

import java.lang.reflect.Method;

import org.zkoss.zul.Checkbox;
import org.zkoss.zul.Constraint;
import org.zkoss.zul.Window;

import com.flca.frw.util.TransformUtils;
import com.flca.frw.zk.util.Alert;
import com.flca.frw.zk.util.WindowHelper;

public class FormItemBoolCtrl extends Window implements IFormItem {

	private static final long serialVersionUID = -9189363508006446234L;

	private static TransformUtils tu = TransformUtils.getInstance();
	
	private WindowHelper wh = new WindowHelper(this);
	
	public void updateView(Object value) 
	{
		try {
			Checkbox cb = (Checkbox) getFellow("idInput");
			
			Boolean bool = tu.object2Bool(value);
			if (bool != null) {
				cb.setChecked(bool.booleanValue());
			}
		} catch (Exception e) {
			Alert.show("FormItemCtrl.updateView() : " + e);
		}	
	}
	
	public void updateModel(Object aTargetObject, Method setter) 
	{
		try {
			Checkbox cb = (Checkbox) getFellow("idInput");
			
			wh.setValue(new Boolean(cb.isChecked()), setter, aTargetObject);
		} catch (Exception e) {
			Alert.show("fout tijdens FormItemCtrl.updateModel " + e );
		} 
		
	}

	public void validate(Constraint constraint) {
		wh.validate("idInput", constraint);
	}

	public void validateNotEmpty() 
	{
		wh.validateNotEmpty("idInput");
	}
	

	
}
